
/*

Dofile: table13_appendix.do 

Date: Dec. 10, 2016 
Aim: Interaction with a continuous measure 

Input: base_for_reg.dta 
Output: table13_appendix.xls 
Reported in the paper: "Table A.13: Regression Effective Marginal Tax Rate and sh. of intra-firm trade, all firms"

*/  

cd $datapath
use base_for_reg, clear 
sort iso3 
merge m:1 iso3 using remot 
keep if _m==3
drop _m 
egen c=group(pays) 
// pays is the iso2 code of the destination country 

egen fpt=group(siren nc8 type) 
// type is a dummy equal to one if the flow is intra-firm, siren is the firm id, nc8 is the 8-digit product category 


reg luv linveatr linvemtr
keep if e(sample) // allows to work from the same sample (same number of observations) with the two different tax ratess

replace intra_x=intra_x/100
sum intra_x,d 
foreach i in lgdpc ldist tarif dum_hines linvemtr{
g intra_`i'=`i'*intra_x
}


g tp=intra_x>0.99 
g medi=intra_x>0.01 & intra_x<0.99 

foreach i in lgdpc ldist tarif dum_hines linvemtr{
g tp_`i'=`i'*tp
g med_`i'=`i'*medi
}

*** reg with continuous measure of intra-firm trade

global name table13_appendix // name of the xls file where the results are sent 
egen fps=group(fp hs4)
egen sect=group(hs4)
global tax_var intra_linvemtr linvemtr // tax variable and its interaction 
areg luv type intra_x $tax_var if tarif!=. , absorb(fpt) vce(cluster sect)
outreg2  type intra_x  $tax_var intra_tarif tarif intra_lgdpc lgdpc intra_ldist ldist  using  "$resultpath/$name.xls" ,  label e(all) nocons bdec(2) symbol($^{***}$, $^{**}$, $^{*}$) adjr2    replace 

areg luv type intra_x  $tax_var intra_tarif tarif intra_lgdpc lgdpc intra_ldist ldist   , absorb(fpt) vce(cluster sect)
outreg2  type intra_x  $tax_var intra_tarif tarif intra_lgdpc lgdpc intra_ldist ldist    using  "$resultpath/$name.xls" ,  label e(all) nocons bdec(2) symbol($^{***}$, $^{**}$, $^{*}$) adjr2    append 

global tax_var intra_dum_hines dum_hines
areg luv type intra_x  $tax_var intra_tarif tarif intra_lgdpc lgdpc intra_ldist ldist  , absorb(fpt) vce(cluster sect)
outreg2  type intra_x  $tax_var intra_tarif tarif intra_lgdpc lgdpc intra_ldist ldist    using  "$resultpath/$name.xls" ,  label e(all) nocons bdec(2) symbol($^{***}$, $^{**}$, $^{*}$) adjr2   append 

global tax_var intra_dum_hines dum_hines intra_linvemtr linvemtr 
areg luv type intra_x   intra_x $tax_var intra_tarif tarif intra_lgdpc lgdpc intra_ldist ldist    , absorb(fpt) vce(cluster sect)
outreg2  type intra_x  $tax_var intra_tarif tarif intra_lgdpc lgdpc intra_ldist ldist    using  "$resultpath/$name.xls" ,  label e(all) nocons bdec(2) symbol($^{***}$, $^{**}$, $^{*}$) adjr2   append 

areg luv type intra_x  $tax_var intra_tarif tarif intra_lgdpc lgdpc intra_ldist ldist  if dum_hines==0, absorb(fpt) vce(cluster sect)
outreg2  type intra_x  $tax_var intra_tarif tarif intra_lgdpc lgdpc intra_ldist ldist  using  "$resultpath/$name.xls" ,  label e(all) nocons bdec(2) symbol($^{***}$, $^{**}$, $^{*}$) adjr2    append 

global tax_var intra_dum_hines  intra_linvemtr // level variables not included - absorbed by the FE 
reghdfe luv type intra_x $tax_var intra_tarif intra_lgdpc intra_ldist  if tarif!=. , absorb(fpt c) vce(cluster sect)
outreg2  type intra_x  $tax_var intra_tarif tarif intra_lgdpc lgdpc intra_ldist ldist   using  "$resultpath/$name.xls" ,  label e(all) nocons bdec(2) symbol($^{***}$, $^{**}$, $^{*}$) adjr2    append 
